// ActionScript file
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;

import user.moudle.classes.UserImpl;
import user.moudle.interfaces.IUser;
//增加
public function addUser():void{
	this.currentState="addOrEditUser";
}
//修改
public function editUser():void{
	
	if(users.selectedIndex == -1){
		Alert.show("请选择一条记录");					 
		return;
	}else{
		
		this.currentState="addOrEditUser";
		this.userId.text = users.selectedItem.@id;
		this.userName.text = users.selectedItem.@userName;
		this.password.text = users.selectedItem.@password;
		var username1:String = this.users.selectedItem.@userName;
		Alert.show("edit::"+this.users.selectedItem.@userName+"::::"+this.users.selectedItem.@password+":"+ this.users.selectedItem.@id);
	}
}
//删除
public function delUser():void{	 
	if(users.selectedIndex == -1){
		Alert.show("请选择一条记录");					 
		return;
	}else{
		Alert.show("del::"+this.users.selectedItem.@id);
		Alert.show(users.selectedItem.@id);
		var userOperate:IUser = new UserImpl();
		userOperate.delUser(users.selectedItem.@id,function delResultEvent(e:ResultEvent):void{
			Alert.show("删除成功");		
		});	 
		this.queryUser();
	}
}

public function save():void{
	var userOperate:IUser = new UserImpl();
	if(userId.text==""){
		userOperate.addUser(userName.text,password.text,function addResultEvent(e:ResultEvent):void{
			Alert.show("添加成功");		
		});
	}else{
		userOperate.editUser(userId.text,userName.text,password.text,function editResultEvent(e:ResultEvent):void{
			Alert.show("修改成功");		
		});
	}
	this.currentState='';
	userName.text='';
	password.text='';
	queryUser();
}

//查询
public function queryUser():void{
	var userOperate:IUser = new UserImpl();
	userOperate.queryUser(whereSql.text,queryUserList);
}

public function queryUserList(e:ResultEvent):void{ 
	users.dataProvider = e.result as ArrayCollection;
}	